﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Parser;
using Semantics;
using Semantics.Base;

namespace Parser
{
    public partial class MainFrame : Form
    {
        public MainFrame()
        {
            InitializeComponent();
        }

        private void toolStripButtonCorpus_Click(object sender, EventArgs e)
        {
            this.ShowCorpusWindow();
        }

        CorpusWindow CorpusWindow;
        void ShowCorpusWindow()
        {
            try
            {
                if (CorpusWindow == null)
                {
                    CorpusWindow = new CorpusWindow();
                    CorpusWindow.MdiParent = this;
                    CorpusWindow.Show();
                    CorpusWindow.FormClosed += new FormClosedEventHandler(CorpusWindow_FormClosed);
                }
                else
                    CorpusWindow.BringToFront();
            }
            catch (Exception exp)
            {
                MessageBox.Show("Parsing Exception:" + exp.Message);
            }
        }

        void CorpusWindow_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.CorpusWindow = null;
        }

        GraphDifference DictionaryDifference;
        const string DifferenceFilename = "semantics.dif";
        private void ToolStripMenuItemSaveOntologyDifferences_Click(object sender, EventArgs e)
        {
            this.DictionaryDifference.Save(DifferenceFilename);
        }

        private void MainFrame_Load(object sender, EventArgs e)
        {
            try
            {
                Semantics.Example.Parser.Reference.InitializeNLP();
                if (System.IO.File.Exists(DifferenceFilename))
                    DictionaryDifference = GraphDifference.Load(DifferenceFilename);
                else
                    DictionaryDifference = new GraphDifference();
                DictionaryDifference.Attach((Graph)NLP.Dictionary);
            }
            catch (Exception exp)
            {
                MessageBox.Show("Parsing Exception:" + exp.Message);
            }
        }

        private void toolStripButtonDictionary_Click(object sender, EventArgs e)
        {
            NLP.ShowClassHierarchy();
        }

    }
}
